package com.woniuxy.yogaapp.mapper;/*
 *@author：源
 *@date:11:40:52
 *@descripion
 */

import com.woniuxy.yogaapp.dto.Check;
import com.woniuxy.yogaapp.pojo.Chat;
import com.woniuxy.yogaapp.pojo.Coach;
import com.woniuxy.yogaapp.pojo.OrderClass;
import com.woniuxy.yogaapp.pojo.Student;
import org.apache.ibatis.annotations.*;


public interface OrderMapper {
    //插入主订单，参数学员，教练，上课相关，并返回一个oid
    @Insert("insert into orderclass (sid,cid,money,course,courseperiod,coursetime,sname,cname) values(#{sid},#{cid},#{money},#{course},#{courseperiod},#{coursetime},#{sname},#{cname})")
    @Options(useGeneratedKeys=true, keyProperty="oid", keyColumn="oid")
    public int insertOderClass(OrderClass orderClass);
    //插入oid，state
    @Insert("insert into detailorder (state,oid) values (#{currentDetailOrders.state},#{oid})")
    public int insertDetailOrder(OrderClass orderClass);

    @Select("SELECT money from student s INNER JOIN pocket p on s.uid=p.puid WHERE sid=#{sid}")
    public OrderClass selectMoney(OrderClass orderClass);

    @Update("UPDATE student s INNER JOIN pocket p on s.uid=p.puid  SET money=#{money} WHERE sid=#{sid}")
    public int updateMoney(OrderClass orderClass);
    @Insert("update detailorder set paytime=#{currentDetailOrders.paytime},state=#{currentDetailOrders.state} where oid=#{oid} and detailoid=#{detailoid}")
    public int updatePayTime(OrderClass orderClass);

    @Select("SELECT money from  pocket WHERE puid=1")
    public OrderClass selectAdminMoney();
    @Update("update pocket set money=#{money} where puid=3")
    public int updateAdminMoney(OrderClass orderClass);

    @Select("SELECT p.money from coach c INNER JOIN pocket p on c.uid=p.puid WHERE cid=#{cid}")
    public OrderClass selectMoneyC(OrderClass orderClass);
    @Update("UPDATE coach s INNER JOIN pocket p on s.uid=p.puid  SET p.money=#{money} WHERE cid=#{cid}")
    public int updateMoneyC(OrderClass orderClass);
    @Insert("update detailorder set completime=#{currentDetailOrders.completime},state=#{currentDetailOrders.state} where oid=#{oid} and detailoid=#{detailoid}")
    public int updateCTime(OrderClass orderClass);
    //检测是否有未处理的订单
    @Select("SELECT * FROM orderclass o INNER JOIN detailorder d ON o.oid=d.oid WHERE sid=#{sid} AND cid =#{cid} AND state=1")
    public Check selectishave(OrderClass orderClass);
    //
    @Update("UPDATE orderclass o INNER JOIN detailorder d ON o.oid=d.oid SET money=#{money},course=#{course},coursetime=#{coursetime},courseperiod=#{courseperiod} WHERE sid=#{sid} AND cid =#{cid} AND state=#{currentDetailOrders.state}")
    public int reupdate(OrderClass orderClass);
   /* //在小订单中插入主订单的id
    @Update("update detailorder set oid=#{oid} where detailoid=#{detailoid}")
    public int insertoid(OrderClass orderClass);*/
   //通知教练存入信息表
    @Insert("insert into chat (sender,recipient,mes,state,mestime,mestype) values(#{sender},#{recipient},#{mes},#{state},#{mestime},#{mestype})")
    public int insertChat(Chat chat);
    //查询教练的电话号码用于发送短信给教练
    @Select("select ctel,cnickname,cname from coach where cid=#{cid}")
    public Coach seletCtelById(OrderClass orderClass);
    @Select("select sname from student where sid=#{sid}")
    public Student seletSnameById(OrderClass orderClass);
}
